import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * This class represents a MessageBox Dialog presented to the User.
 * <br />
 * This class is losely based on the "Dialog Demo" Scenario by mjrb4 (www.greenfoot.org/scenarios/199)
 * 
 * @author (Thomas KOBER) 
 * @author (Dilyan GEORGIEV)
 * 
 * @version (1.0)
 */
public class MessageBox extends Actor
{
    private static final int WIDTH   = 700;
    private static final int HEIGHT  = 500;

    /**
     * Constructor for objects of class MessageBox.
     * @param contents ArrayList of Message objects representing the contents to be displayed.
     */
    public MessageBox(ArrayList<Message> contents)
    {
        GreenfootImage image = super.getImage();
       
        for (Message msg : contents) {
            image.setFont(msg.getFont());
            image.setColor(msg.getTextColor());
            
            image.drawString(msg.getText(), (int)msg.getPosition().getX(), (int)msg.getPosition().getY());
        }
        
        GreenfootImage btnOk = new GreenfootImage("OkButton.png");
        
        image.drawImage(btnOk, 280, 400);
        
        super.setImage(image);
    }
    
    /**
     * Remove Message on click.
     */
    public void act() 
    {
        MouseInfo mouse = Greenfoot.getMouseInfo();
        if (mouse == null) return;
        if (mouse.getActor() == this && mouse.getButton() == 1)  {
             ((StackWorld)super.getWorld()).setPaused(false);
             super.getWorld().removeObject(this);
        }
    }    
}
